import sys
import numpy

id_string = '$Id: giangiotto.py 102 2013-05-03 11:43:27Z 86gda86@gmail.com $'

def check_line( input_string, atom):
    if input_string.startswith('ATOM'):
	if input_string.split()[2] == atom:
	   return input_string
    return ''


print 'first python script'

file_name = sys.argv[1] #giving argument from the shell, like the name of the file to be opened

temp = open(file_name, 'r')

text_lines = temp.readlines()

#for line in text_lines:
#    if line.startswith('ATOM'):
#	lista = line.split()
#        #count = 0
#        for i in range(len(lista)):
#	    if lista[i] == 'H':
#                #count = 1
#                print line.strip()

x_values = []
y_values = []
z_values = []

for line in text_lines:
    if check_line(line,'C') != '':
	line_list = line.split()
	x_values.append(float(line_list[4]))
	y_values.append(float(line_list[5]))
	z_values.append(float(line_list[6]))
	#print line.strip('\n')

import numpy

x_average = numpy.mean (x_values)

print 'The values of coordinates are: '
print x_values
print y_values
print z_values
print ''
print 'The average of the x values is: '
print x_average
